package com.cskaoyan.service;

import com.cskaoyan.bean.stat.StatInfo.StatInfo;
import com.cskaoyan.bean.stat.StatOfUser.StatOfUser;
import com.cskaoyan.mapper.StatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author looper
 * @
 **/
@Service
public class StatServiceImpl implements StatService {

    @Resource
    StatMapper mapper;

    @Override
    public StatOfUser getStatOfUser() {
        //返回所有的时间点和用户数量
       List<StatInfo> rows = mapper.selectUserStat();
       //一个枚举类型的集合代表字段名
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");
        //包装类返回
        StatOfUser statOfUser = new StatOfUser();
        statOfUser.setColumns(columns);
        statOfUser.setRows(rows);
        return  statOfUser;

    }

    @Override
    public StatOfUser getStatOfOrder() {
        List<StatInfo> rows =  mapper.selectOrderStat();
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");
        //包装类返回
        StatOfUser statOfUser = new StatOfUser();
        statOfUser.setColumns(columns);
        statOfUser.setRows(rows);
        return  statOfUser;

    }

    @Override
    public StatOfUser getStatOfGoods() {
        List<StatInfo> rows =  mapper.selectGoodsStat();
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        //包装类返回
        StatOfUser statOfUser = new StatOfUser();
        statOfUser.setColumns(columns);
        statOfUser.setRows(rows);
        return  statOfUser;

    }


}
